﻿#region  文件信息

// ---------------------------------------------------------------------------------------
// <copyright file="RandomsAzNum.cs" company="">
// 作者：李帅伦
// </copyright>
// <summary>
// 类型简介：
// 类型详细：RandomsAzNum.cs
// 创建时间：2014-05-15 16:36
// 修改时间：2014-05-15 15:40
// </summary>
// ---------------------------------------------------------------------------------------

#endregion

using System;
using System.Text;

namespace LsTool
{
    #region



    #endregion
    /// <summary>
    /// 随机数获取
    /// </summary>
    public class RandomsAzNum
    {
        #region Constants

        private const string AzLower = "qwertyuiopasdfghjklzxcvbnm";

        private const string AzUpper = "QWERTYUIOPASDFGHJKLZXCVBNM";

        private const string Num = "0123456789";

        #endregion

        #region Fields

        private static readonly Random random = new Random();


        #endregion

        #region Constructors and Destructors
        /// <summary>
        /// 默认10长度
        /// </summary>
        public RandomsAzNum(int length = 10)
        {
            this.Length = length;
        }

        #endregion

        #region Public Properties
        /// <summary>
        /// 设置扩展字符
        /// </summary>
         string Ex { get; set; }
        /// <summary>
        /// 设置随机字符串长度
        /// </summary>
         int Length { get; set; }

        #endregion

        #region Public Methods and Operators



        /// <summary>
        /// 获取所有大写字母
        /// </summary>
        /// <returns></returns>
         string GetAzLower
        {
            get
            {
                return AzLower;
            }
        }
        /// <summary>
        /// 获取所有小写字母
        /// </summary>
        /// <returns></returns>
         string GetAzUpper
        {
            get
            {
                return AzUpper;
            }
        }


        /// <summary>
        /// 获取数字
        /// </summary>
        /// <returns></returns>
         string GetNum
        {
            get
            {
                return Num;
            }
        }

   
        /// <summary>
        /// 获取随机扩展
        /// </summary>
        /// <returns></returns>
        /// <returns></returns>
        string OutputEx()
        {
            return this.Output(this.Ex);
        }
     

        #endregion

        #region Methods

        private string Output(string str)
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < this.Length; i++)
            {
                int next = random.Next(0, str.Length);
                string substring = str.Substring(next, 1);
                sb.Append(substring);
            }
            return sb.ToString();
        }

        #endregion

        /// <summary>
        /// 获取随机大小写
        /// </summary>
        /// <param name="length">位数</param>
        /// <returns></returns>
        public static string GetLu(int length)
        {
            var randomsAzNum = new RandomsAzNum(length);
            randomsAzNum.Ex = randomsAzNum.GetAzLower + randomsAzNum.GetAzUpper;
            return randomsAzNum.OutputEx();
        }

        /// <summary>
        /// 获取随机大写+数字
        /// </summary>
        /// <param name="length">位数</param>
        /// <returns></returns>
        public static string GetUn(int length)
        {
            var randomsAzNum = new RandomsAzNum(length);
            randomsAzNum.Ex = randomsAzNum.GetNum + randomsAzNum.GetAzUpper;
            return randomsAzNum.OutputEx();
        }

        /// <summary>
        /// 获取随机小写+数字
        /// </summary>
        /// <param name="length">位数</param>
        /// <returns></returns>
        public static string GetLn(int length)
        {
            var randomsAzNum = new RandomsAzNum(length);
            randomsAzNum.Ex = randomsAzNum.GetAzLower + randomsAzNum.GetNum;
            return randomsAzNum.OutputEx();
        }

        /// <summary>
        /// 获取随机大、小写、数字
        /// </summary>
        /// <param name="length">位数</param>
        /// <returns></returns>
        public static string GetLun(int length)
        {
            var randomsAzNum = new RandomsAzNum(length);
            randomsAzNum.Ex = randomsAzNum.GetAzLower + randomsAzNum.GetAzUpper + randomsAzNum.GetNum;
            return randomsAzNum.OutputEx();
        }

        /// <summary>
        /// 获取随机、数字
        /// </summary>
        /// <param name="length">位数</param>
        /// <returns></returns>
        public static string GetN(int length)
        {
            var randomsAzNum = new RandomsAzNum(length);
            randomsAzNum.Ex = randomsAzNum.GetNum;
            return randomsAzNum.OutputEx();
        }
    }
}